<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Gets the name of the XML element</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="simplexmlelement.getdocnamespaces.html">« SimpleXMLElement::getDocNamespaces</a></li>
      <li style="float: right;"><a href="simplexmlelement.getnamespaces.html">SimpleXMLElement::getNamespaces »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.simplexmlelement.html">SimpleXMLElement</a></li>
    <li>Gets the name of the XML element</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="simplexmlelement.getname" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SimpleXMLElement::getName</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.3, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">SimpleXMLElement::getName</span> &mdash; <span class="dc-title">Gets the name of the XML element</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-simplexmlelement.getname-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SimpleXMLElement::getName</strong></span>(): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   Gets the name of the XML element.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-simplexmlelement.getname-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-simplexmlelement.getname-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The <code class="literal">getName</code> method returns as a <span class="type">string</span> the 
   name of the XML tag referenced by the SimpleXMLElement object.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-simplexmlelement.getname-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <blockquote class="note"><p><strong class="note">注意</strong>: 
    <p class="para">
     Listed examples may include <code class="literal">example.php</code>,
     which refers to the XML string found in the first example
     of the <a href="simplexml.examples-basic.html" class="link">basic usage</a> guide.
    </p>
   </p></blockquote>
   <div class="example" id="example-5461">
    <p><strong>示例 #1 Get XML element names</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">'example.php'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$sxe&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlstr</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">$sxe</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getName</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br />foreach&nbsp;(</span><span style="color: #0000BB">$sxe</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">children</span><span style="color: #007700">()&nbsp;as&nbsp;</span><span style="color: #0000BB">$child</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$child</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getName</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
movies
movie
</pre></div>
    </div>
   </div>
  </p>
 </div>


</div></div></div></body></html>